package com.xingxuecn.demos.common;


import org.apache.log4j.Logger;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * 生产和存储RowMapper对象的
 * @author Kris at 2018/9/27 16:37
 */
public class RowMapperFactory {
    static Logger logger = Logger.getLogger(RowMapperFactory.class);

    private static Map<Class,RowMapper> map = new HashMap<Class, RowMapper>();

    public static RowMapper getRowMapper(Class clazz){
        RowMapper rowMapper = map.get(clazz);
        if(rowMapper == null){
            rowMapper = new BeanPropertyRowMapper(clazz);
            map.put(clazz,rowMapper);
            logger.info("init RowMapper for Class:"+clazz.getName());
        }
        return rowMapper;
    }
}
